'''
Copyright: 
Descripttion: 
version: 
Author: chengx
Date: 2021-05-22 21:46:22
LastEditors: chengx
LastEditTime: 2021-07-16 10:30:22
'''
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from random import randint
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtCore import QTimer,QSize
from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QProgressBar,QHBoxLayout,QDesktopWidget
import time
from PyQt5.QtGui import QColor, QPainter, QFont

StyleSheet = '''
#BlueProgressBar {
    border: 2px solid #2196F3;/*边框以及边框颜色*/
    border-radius: 5px;
    background-color: #E0E0E0;
}
#BlueProgressBar::chunk {
    background-color: #2196F3;
    width: 10px; /*区块宽度*/
    margin: 0.5px;
}
'''

class CircleProgressBar(QWidget):#传统圆圈

    Color = QColor(24, 189, 155)  # 圆圈颜色
    Clockwise = True  # 顺时针还是逆时针
    Delta = 36

    def __init__(self, *args, color=None, clockwise=True, **kwargs):
        super(CircleProgressBar, self).__init__(*args, **kwargs)
        self.angle = 0
        self.Clockwise = clockwise
        if color:
            self.Color = color
        self._timer = QTimer(self, timeout=self.update)
        self._timer.start(100)

    def paintEvent(self, event):
        super(CircleProgressBar, self).paintEvent(event)
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.translate(self.width() / 2, self.height() / 2)
        side = min(self.width(), self.height())
        painter.scale(side / 100.0, side / 100.0)
        painter.rotate(self.angle)
        painter.save()
        painter.setPen(Qt.NoPen)
        color = self.Color.toRgb()
        for i in range(11):
            color.setAlphaF(1.0 * i / 10)
            painter.setBrush(color)
            painter.drawEllipse(30, -10, 20, 20)
            painter.rotate(36)
        painter.restore()
        self.angle += self.Delta if self.Clockwise else -self.Delta
        self.angle %= 360


    # @pyqtProperty(bool)
    def clockwise(self) -> bool:
        return self.Clockwise

    # @clockwise.setter
    def clockwise(self, clockwise: bool):
        if self.Clockwise != clockwise:
            self.Clockwise = clockwise
            self.update()

    # @pyqtProperty(int)
    def delta(self) -> int:
        return self.Delta

    # @delta.setter
    def delta(self, delta: int):
        if self.delta != delta:
            self.delta = delta
            self.update()

    def sizeHint(self) -> QSize:
        return QSize(200, 200)

class my_Circle(QWidget):

    def __init__(self, *args, **kwargs):
        super(my_Circle, self).__init__(*args, **kwargs)
        
        self.setWindowOpacity(0.8)#透明度
        self.setWindowFlags(Qt.FramelessWindowHint)#去菜单栏
        self.setAttribute(Qt.WA_TranslucentBackground, True)#去边框
        
        screen = QDesktopWidget().screenGeometry()
        newLeft = (screen.width() - 222) / 2
        newTop = (screen.height() - 222) / 2
        self.move(int(newLeft),int(newTop))
        self.setWindowModality(Qt.ApplicationModal) # 设置模态

        layout = QHBoxLayout(self)
        layout.addWidget(CircleProgressBar(self))
        
if __name__ == "__main__":
    app = QApplication(sys.argv)
    app.setStyleSheet(StyleSheet)

    w = my_Circle()
    w.show()
    sys.exit(app.exec_())
